﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MediaController.Client.DAL;
using System.Text.RegularExpressions;

namespace MediaController.Client.Controls.Dialogs
{
    public partial class DestinationBuilder : Form
    {
        private readonly int _categoryId;

        public string Destination { get; set; }

        public DestinationBuilder(int categoryId)
        {
            _categoryId = categoryId;
            InitializeComponent();
        }

        private void DestinationBuilder_Load(object sender, EventArgs e)
        {
            _textBoxDestination.Text = Destination;
            //var categoriesRow = DataAccess.Instance.MediaControllerDataSet.Categories.FindById(_categoryId);
            //var regexRows = categoriesRow.GetRegexRows();
            var groups = new Dictionary<string, string>();
            groups.Add("Directory", "Directory");
            groups.Add("FileName", "FileName");
            groups.Add("MediaName", "MediaName");
            //foreach (var regexRow in regexRows)
            //{
            //    var matches = Regex.Matches(regexRow.Regex, @"<\w+>");
            //    foreach (Match match in matches)
            //    {
            //        string value = match.Value.Trim('<', '>');
            //        if (!groups.ContainsKey(value))
            //        {
            //            groups.Add(value, value);
            //        }
            //    }
            //}

            foreach (var @group in groups)
            {
                _listBoxMacro.Items.Add(@group.Key);
            }
        }

        private void ButtonAddClick(object sender, EventArgs e)
        {
            string value = _listBoxMacro.SelectedItem.ToString();
            _textBoxDestination.AppendText(string.Format("<{0}>", value));
        }

        private void ListBoxMacroSelectedIndexChanged(object sender, EventArgs e)
        {
            _buttonAdd.Enabled = true;
        }

        private void ButtonOkClick(object sender, EventArgs e)
        {
            Destination = _textBoxDestination.Text;
        }
    }
}
